﻿<!-- Phan khai bao bien cuc bo-->
<?php
//Luu giu dieu kien loc
$v_page=1;
if(isset($_REQUEST['hdn_page'])){
	$v_page=intval($_REQUEST['hdn_page']);
}
//Bien luu so dong tren mot trang
$v_limit_row = 1;
if(isset($_REQUEST['hdn_record_number_page'])){
	$v_limit_row = intval($_REQUEST['hdn_record_number_page']);
}
if(isset($_REQUEST['fuseaction_back'])) {
	$fuseaction_back=$_REQUEST['fuseaction_back'];
}else{
	$fuseaction_back = $fuseaction;
}
$v_recordtype_filter = $_SESSION['onegate_current_recordtype'];
$v_staff_id = $_SESSION['staff_id'];
$v_recordtype_name = Get_text_from_array($_SESSION['recordtype'],'PK_RECORDTYPE','PK_RECORDTYPE','C_NAME',$v_recordtype_filter);
$v_str_SQL  = "ONEGATE_ListGetAllbyCode 'NOI_DUNG_MAIL'";
$arr_all_mail_content = Query_Data_For_Colunm_name($v_str_SQL);
//var_dump($arr_all_record);
//var_dump($arr_all_mail_content);
$v_replace_xml_file = "../../xml/".$v_recordtype_filter."/mau_gui_email_thong_bao_toi_cong_dan.xml";
if (file_exists($v_replace_xml_file) && file_exists($v_replace_xml_file)){
	$v_replace_xml_string = _read_file($v_replace_xml_file);
}else{
	$v_replace_xml_file = "../../xml/other/mau_gui_email_thong_bao_toi_cong_dan.xml";
	$v_replace_xml_string = _read_file($v_replace_xml_file);
}

$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_replace_xml_string);
$table_struct_rax->record_delim = 'application_form';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
$table_struct_row = $table_struct_rec->getRow();
$v_email_tag_in_db = $table_struct_row["email_tag_in_db"];

$v_record_code_list='';
$v_record_id_list = '';
for($row_index = 0;$row_index< $v_count;$row_index++){
	$v_record_code_list = _list_add($v_record_code_list,$arr_all_record[$row_index]['C_CODE'],", ");
	$v_record_id_list = _list_add($v_record_id_list,$arr_all_record[$row_index]['PK_RECORD'],",");
}
// xac dinh label hien thi: trinh ky, duoc giai quyet, khong duoc giai quyet
$arr_result_label = onegate_get_label_of_result_type($_SESSION['recordtype'],$v_recordtype_filter);

?>
<!--bang chua tieu de cua form-->
<table width="100%" cellpadding="0" cellspacing="0">
	<tr class="large_title">
		<td><?php echo _CONST_SEND_EMAIL_TITLE; ?></td>
	</tr>
</table>
<!-- Bat cac phim: F12=true; Insert=false; Delete=false, ESC=true; Enter=true -->
<div id="hotkey" onKeyDown="javascript:process_hot_key(true,false,false,true,true);">
<!--bang chua cac text box de nhap du lieu-->
<table width="100%" class="form_table1" cellpadding="0" cellspacing="0">
	<col width="15%"><col width="65%"><col width="20%">
	<tr>
		<form action="index.php" method="post" name="f_all_record_for_send_mail">
		<input type="hidden" name="fuseaction" value="" >
		<input type="hidden" name="fuseaction_back" value="<?php echo $fuseaction_back; ?>">
		<input type="hidden" name="hdn_record_id_list" value="<?php echo $v_record_id_list ?>" >
		<input type="hidden" name="hdn_recordtype_filter" value="<?php echo $v_recordtype_filter;?>">
		<input type="hidden" name="hdn_work" value="">
		<input type="hidden" name="hdn_email_list" value="<?php echo $v_email_list;?>">
		<input type="hidden" name="hdn_email_content" value="<?php echo $v_list_name;?>">
		<input type='hidden' name='hdn_page' value='<?php echo $v_page;?>'>
		<input type='hidden' name='hdn_record_number_page' value='<?php echo $v_limit_row;?>'>
	</tr>
	<tr>
	<tr>
		<td class="normal_label"><?php echo CONST_RECORD_TYPE_LABEL; ?></td>
		<td><?php echo $v_recordtype_name;?></td>
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_LIST_RECORD_LABEL; ?></td>
		<td><?php echo $v_record_code_list;?></td>
	</tr><?php
	$v_have_email = false;
	for($row_index = 0;$row_index< $v_count;$row_index++){
		$v_record_id = $arr_all_record[$row_index]['PK_RECORD']; 
		$v_current_status = $arr_all_record[$row_index]['C_CURRENT_STATUS']; 
		$v_detail_status = $arr_all_record[$row_index]['C_DETAIL_STATUS'];		
		$v_xml_str = $arr_all_record[$row_index]['C_RECEIVED_RECORD_XML_DATA'];  //
		if ($v_xml_str!=""){
			$column_rax = new RAX(); 
			$column_rec = new RAX();
			$column_rax->open($v_xml_str);
			$column_rax->record_delim = 'data_list';
			$column_rax->parse();
			$column_rec = $column_rax->readRecord(); 
			$column_row = $column_rec->getRow();
			$v_email = _restore_XML_bad_char($column_row[$v_email_tag_in_db]); 
		}
		if (trim($v_email) == ""){
			$v_email = "<small class='normal_starmark'>" . CONST_RECORD_NO_EMAIL_LABEL . "</small>";
		}else{
			$v_have_email = true;
		}
		if ($v_current_status == "CAP_PHEP" && $v_detail_status == 61) {
			$v_current_status = "61";
		}
		switch($v_current_status) {
			case "61";
				$v_email_content = "";
				for ($i=0;$i<sizeof($arr_all_mail_content);$i++){
					if (trim($arr_all_mail_content[$i]['C_CODE'])=="TB_HO_SO_BI_THU_HOI"){
						$v_email_content = $arr_all_mail_content[$i]['C_NAME'];					
					}
				}
				break;
			case "CAP_PHEP";
				$v_email_content = "";
				for ($i=0;$i<sizeof($arr_all_mail_content);$i++){
					if (trim($arr_all_mail_content[$i]['C_CODE'])=="TB_HO_SO_DA_GIAI_QUYET"){
						$v_email_content = $arr_all_mail_content[$i]['C_NAME'];					
					}
				}
				break;
			case "TU_CHOI";
				$v_email_content = "";
				for ($i=0;$i<sizeof($arr_all_mail_content);$i++){
					if (trim($arr_all_mail_content[$i]['C_CODE'])=="TB_HO_SO_BI_TU_CHOI"){
						$v_email_content = $arr_all_mail_content[$i]['C_NAME'];					
					}
				}
				break;
			case "DANG_THU_LY";
				$v_email_content = "";
				for ($i=0;$i<sizeof($arr_all_mail_content);$i++){
					if (trim($arr_all_mail_content[$i]['C_CODE'])=="TB_BO_SUNG_HO_SO"){
						$v_email_content = $arr_all_mail_content[$i]['C_NAME'];					
					}
				}
				break;
		}
		$v_email_content = Print_Receipt_From_XML($v_replace_xml_string,$v_email_content,$v_xml_str,$arr_all_record[$row_index]);
		?>
		<tr><td colspan="10" ><hr color="#66CCFF" size="1"></td></tr>
		<tr>
			<td class="normal_label"><?php echo _CONST_LIST_EMAIL_LABEL; ?></td>
			<td><?php echo $v_email;?>
				<input type="hidden" name="hdn_email_<?php echo $v_record_id;?>" value="<?php echo $v_email;?>">
			</td>
		</tr>
		<tr class="normal_label">
			<td class="normal_label"><?php echo _CONST_EMAIL_CONTENT_LABEL; ?></td>
			<td><textarea name = "hdn_email_content_<?php echo $v_record_id;?>" value = "" class="normal_textarea" rows="5" optional="true" style="width:100%" message =""><?php echo $v_email_content;?></textarea></td>
		</tr>
		<?php
	}
	if (!$v_have_email){ ?>
	<tr>
		<td class="normal_label" colspan="5"><small class='normal_starmark'><?php echo _CONST_ANY_ONE_HAVE_NO_EMAIL_LABEL; ?></small></td>
	</tr><?php
	}?>
</table>
<?php
//}
?>
<!--bang chua cac button-->
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr><td>&nbsp;</td></tr>
	<tr align="center">
		<td><?php
			if ($v_have_email && (($v_is_granted_update)||onegate_is_handler_for_recordtype($v_staff_id,$v_recordtype_filter,$_SESSION["recordtype"]))){?>
				<input type="button" name="btn_save"  class="normal_button" value="<?php echo _CONST_ACT_SEND_BUTTON;?>" onClick="sending_email('SENDING_EMAIL')" onKeyDown="change_focus(document.forms(0),this)"><?php
			}?>
			<input type="button" name="btn_back" class="normal_button" value="<?php echo _CONST_BACK_BUTTON;?>" onClick="btn_back_onclick('<?php echo $_GO_BACK?>')" onKeyDown="change_focus(document.forms(0),this)">
			
		</td>
	</tr>
</table>					
</div>
</form>
<script language="JavaScript">
	set_focus(document.forms(0));
</script>
